package codetop.huawei.T1004;

/**
 * @Author: 18362
 * @Create: 2022-09-12 18:29:40 星期一
 */
class Solution {
    public int longestOnes(int[] nums, int k) {
        int left = 0, right = 0, num0 = 0, maxLen = 0;
        while (right < nums.length) {
            if (nums[right++] == 0)
                num0++;
            if (num0 <= k)
                maxLen = Math.max(maxLen, right - left);
            while (num0 > k) {
                if (nums[left++] == 0)
                    num0--;
            }
        }
        return maxLen;
    }
}